// 请求封装
import axios from "axios";
//从仓库获取用户数据
import pinia from "@/store/index";
import {useLogin} from "@/store/login"

// 新建axios实例
const request = axios.create({
    baseURL:"http://localhost:3000/app-dev",
    timeout:5000,
})

// 请求拦截
request.interceptors.request.use((config:any)=>{
    //获取pinia模块中的token
    const token = useLogin(pinia).token;
    if (token){
        (config.headers as any).token = token;
    }
    return config;
})

// 响应拦截
request.interceptors.response.use(
    (response:any) => {
        return response.data;
    },
    (error) => {
        return new Promise(() => {});
    }
);
export default request
